<template>
	<view class="news">
		<view class="news_item" v-for="(item, index) in news" :key="index" @click="navigator(item.id)">
			<image src="../../static/254542c348e0401b7133784724f50cea.jpg" mode="aspectFill"></image>
			<view class="right">
				<view class="title">
					{{item.title}}
				</view>
				<view class="info">
					<!-- 使用过滤器 -->
					<text>发表时间: {{item.add_time | formatDate}}</text>
					<text>浏览量: {{item.click}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "news-list",
		props: ['news'],
		filters: {
			// 格式化时间
			formatDate(date) {
				const nDate = new Date(date)
				return nDate.getTime()
			}
		},
		methods: {
			// 接受父组件的事件
			navigator(id) {
				// 传值给父组件 id  itemClick 父组件使用@itemClick 方式来接受事件
				this.$emit('itemClick', id)
				console.log("接受父组件1")
			}
		}
	}
</script>

<style lang="scss">
	.news {
		.news_item {
			display: flex;
			border-bottom: 1px solid $shop-color;
			padding: 10rpx 20rpx;

			image {
				width: 200rpx;
				height: 150rpx;
			}

			.right {
				margin-left: 10rpx;
				display: flex;
				justify-content: space-between;
				flex-direction: column;

				.title {
					font-size: 30rpx;

				}

				.info {
					font-size: 24rpx;

					text:nth-child(2) {
						margin-left: 30rpx;
					}
				}
			}
		}
	}
</style>
